package com.youlai.boot.factory.controller;

import com.youlai.boot.factory.service.ClothingSizesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.factory.model.form.ClothingSizesForm;
import com.youlai.boot.factory.model.query.ClothingSizesQuery;
import com.youlai.boot.factory.model.vo.ClothingSizesVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 服装尺码前端控制层
 *
 * @author youlaitech
 * @since 2025-07-14 18:46
 */
@Tag(name = "服装尺码接口")
@RestController
@RequestMapping("/api/v1/clothing-sizes")
@RequiredArgsConstructor
public class ClothingSizesController  {

    private final ClothingSizesService clothingSizesService;

    @Operation(summary = "服装尺码分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('factory:clothing-sizes:query')")
    public PageResult<ClothingSizesVO> getClothingSizesPage(ClothingSizesQuery queryParams ) {
        IPage<ClothingSizesVO> result = clothingSizesService.getClothingSizesPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增服装尺码")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('factory:clothing-sizes:add')")
    public Result<Void> saveClothingSizes(@RequestBody @Valid ClothingSizesForm formData ) {
        boolean result = clothingSizesService.saveClothingSizes(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取服装尺码表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('factory:clothing-sizes:edit')")
    public Result<ClothingSizesForm> getClothingSizesForm(
        @Parameter(description = "服装尺码ID") @PathVariable Long id
    ) {
        ClothingSizesForm formData = clothingSizesService.getClothingSizesFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改服装尺码")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('factory:clothing-sizes:edit')")
    public Result<Void> updateClothingSizes(
            @Parameter(description = "服装尺码ID") @PathVariable Long id,
            @RequestBody @Validated ClothingSizesForm formData
    ) {
        boolean result = clothingSizesService.updateClothingSizes(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除服装尺码")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('factory:clothing-sizes:delete')")
    public Result<Void> deleteClothingSizess(
        @Parameter(description = "服装尺码ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = clothingSizesService.deleteClothingSizess(ids);
        return Result.judge(result);
    }
}
